#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 500010;
const int M = 500010;
ll n,m;
ll ans = 0,edge_cnt = 0;
ll father[N] = {0};
ll get_father(ll x){
    if(father[x] == x)return x;
    return father[x] = get_father(father[x]);
}
void union_(ll x,ll y){
    father[get_father(y)] = get_father(x);
}
bool find(ll x,ll y){
    if(get_father(x) == get_father(y))return true;
    return false;
}
struct GraphEdge{
    ll u,v,w;
    GraphEdge(){}
    GraphEdge(ll x,ll y,ll z) : u(x) , v(y) , w(z) {}
}edge[M];
bool cmp(GraphEdge a,GraphEdge b){
    return a.w < b.w;
}
int main(){
    scanf("%lld%lld",&n,&m);
    ll u,v,w;
    for(ll i = 1;i <= m;i++){
        scanf("%lld%lld%lld",&u,&v,&w);
        edge[i] = GraphEdge(u,v,w);
    }
    for(ll i = 1;i <= n;i++)father[i] = i;
    sort(edge + 1,edge + 1 + m,cmp);
    for(ll i = 1;i <= m;i++){
        if(!find(edge[i].u,edge[i].v)){
            ans += edge[i].w;
            edge_cnt++;
            union_(edge[i].u,edge[i].v);
        }
        if(edge_cnt == n - 1)break;
    }
    if(edge_cnt != n - 1)printf("orz\n");
    else printf("%lld\n",ans);
    return 0;
}